{extend name="template/base" /}
{block name="nav"}{/block}
{block name="content"}
<div style="margin-top:20px;"  class="page-container">
	<div class="toptip">
		<h2>提示：</h2>
		<p>
		  填写用户真实有效信息，星号栏为必填项<br>
		</p>
	</div>
	<legend><i class="Hui-iconfont">&#xe600;</i>用户管理</legend>
    <form class="form form-horizontal" id="form" method="post" action="{:\\think\\Request::instance()->baseUrl()}">
        <input type="hidden" name="userid" value="{$user.userid ?? ''}">
<!--         <div class="row cl">
            <label class="form-label f-l ml-20"><span class="c-red">*</span>帐号：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" {present name="vo.username"} value="{$vo.username}" readonly {else /}  placeholder="只能是字母数字下划线" {if !$vo} name="username" {/if} datatype="/\w+/" nullmsg="请填写帐号" errormsg="帐号只能是字母数字下划线" {/present}>
            </div>
            <div  class="col-xs-offset-4">{present name="vo.username"}<span class="label label-warning radius">不可更改</span>{/present}</div>
        </div> -->

        <div class="row cl">
            <label class="form-label f-l ml-20"><span class="c-red">*</span>姓名：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$user.realname ?? ''}" {if $user.realname!=''}readonly{/if} placeholder="" name="user[realname]" datatype="*" nullmsg="请填写姓名">
            </div>
            <div class="col-xs-offset-4"></div>
        </div>
        {notpresent name="vo.password"}
       <!-- <div class="row cl">
            <label class="form-label f-l ml-20"><span class="c-red"></span>密码：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="password"  class="input-text" placeholder="留空或不填写密码默认为{:\\think\\Config::get('site.default_password')}" name="user[password]" datatype="/^[\w\W]{6,32}$/" ignore="ignore" value="{$user.userid ? 'nonepassword' : ''}" nullmsg="请填写6-12位密码" errormsg="请填写6-32位任意字符">
            </div>
            <div class="col-xs-offset-4"></div>
        </div>-->
        {/notpresent}
      <!--  <div class="row cl">
		
            <label class="form-label f-l ml-20">邮箱：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$user.email ?? ''}" placeholder="请填写邮箱,如 admin@163.com" name="user[email]" datatype="e" ignore="ignore" errormsg="邮箱格式错误">
            </div>
            <div class="col-xs-offset-4"></div>
        </div>-->
       
        <div class="row cl">
            <label class="form-label f-l ml-20"><span class="c-red">*</span>身份证：</label>
            <div class="formControls col-xs-6 col-sm-6">
			 <input type="hidden"  class="input-text" placeholder="留空或不填写密码默认为{:\\think\\Config::get('site.default_password')}" name="user[password]" datatype="/^[\w\W]{6,32}$/" ignore="ignore"value="{$user.userid ? 'nonepassword' : '123456'}" nullmsg="请填写6-12位密码" errormsg="请填写6-32位任意字符">
			 <input type="hidden" class="input-text" value="{$user.email ?? ''}" placeholder="请填写邮箱,如 admin@163.com" name="user[email]" datatype="e" ignore="ignore" errormsg="邮箱格式错误">
                <input type="text" class="input-text" name="user[idcard]"  {if $user.idcard !=''}readonly{/if}  value="{$user.idcard ?? ''}" placeholder="请填写身份证" datatype="idcard" errormsg="您填写的身份证号码不对！">
            </div>
            <div class="col-xs-offset-4"></div>
        </div>
		 <div class="row cl">
            <label class="form-label f-l ml-20">联系手机：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$usercompany.contact_phone ?? ''}" placeholder="请填写手机号码" name="usercompany[contact_phone]" datatype="m" ignore="ignore" errormsg="手机格式错误">
            </div>
            <div class="col-xs-offset-4"></div>
        </div>
        <div class="row cl">
            <label class="form-label f-l ml-20">职位：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$usercompany.position}" placeholder="请填写人员职位,如法人代表，技术负责人等" name="usercompany[position]">
            </div>
              <div class="col-xs-offset-4"></div>
        </div>
        <!-- <div class="row cl">
            <label class="form-label f-l ml-20">所在地：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$usercompany.address ?? ''}" placeholder="请填写人员所在地址" name="usercompany[address]">
            </div>
              <div class="col-xs-offset-4"></div>
        </div> -->
<!--         <div class="form form-horizontal">
            <div class="row cl">
                <label class="form-label f-l ml-20">留底照片：</label>
                <div class="formControls col-xs-6 col-sm-6">
                    <input name="user[photo_collect]" value="{$user.photo_collect ?? ''}" type="text" class="input-text" id="upload" placeholder="请点击后面的上传按钮" style="width: 70%">
                    <button type="button" class="btn btn-primary radius" onclick="layer_open('文件上传','{:\\think\\Url::build(\'Upload/index\', [\'id\' => \'upload\'])}')">上传</button>
                    <a onclick="$(this).attr('href', $('#upload').val())" type="button" class="btn btn-success radius" data-lightbox="preview">预览</a>
                </div>
                  <div class="col-xs-offset-4"></div>
            </div>
        </div> -->
		 <div class="row cl ">
        <label class="form-label  f-l ml-20">职能：</label>
            <div class="formControls  col-xs-6 col-sm-6">
                <div class="select-box">
                <select  class="select" id='job_title' name="usercompany[job_title]" class="select select-default" onchange='Authority()' >
                    <option value="1">外施工单位</option>
					<option value="2" {if $usercompany.job_title eq '2'} selected {/if} >内勤</option>
                </select>
               </div>
            </div>
            <div class="col-xs-offset-4"></div>
        </div>
        <div class="row cl" style='display:none' >
        <label class="form-label  f-l ml-20">人员组：</label>
            <div class="formControls  col-xs-6 col-sm-6">
                <div class="select-box">
                <select class="select"  name="usercompany[groupid]" class="select-default">
                    <option value="0">请选择人员分组</option>
                    {if isset($groupList)}
                        {volist name="groupList" id="PList"}
                            <option value="{$PList.id}" {if $PList.id==$usercompany.groupid}selected{/if}>{$PList.name}</option>
                        {/volist}
                    {/if}
                </select>
               </div>
            </div>
            <div class="col-xs-offset-4"></div>
        </div>
       
        <div class="row cl usercompaysc">
             <label class="form-label  f-l ml-20">公司：</label>
                <div class="formControls  col-xs-6 col-sm-6">
                <div class="select-box">
                <select needle="needle" msg="您必须添加选择一种公司" class="select" datatype="*" name="usercompany[company_id]" class="select-default companyid" onchange="getDepartment(this.value)">
                  
                    {if isset($CompanyList)}
                        {volist name="CompanyList" id="cL"}
                        <option value="{$cL.id}" {if $cL.id==$usercompany.company_id}selected{/if}>{$cL.name}</option>
                        {/volist}
					{else}
					  <option value="0">请选择公司</option>
                    {/if}
                </select>
               </div>
            </div>
            <div class="col-xs-offset-4"></div>
        </div>
        <div class="row cl authy " {if $usercompany.job_title neq '2'} style='display:none' {/if} >
              <label class="form-label  f-l ml-20">部门：</label>
                <div class="formControls  col-xs-6 col-sm-6">
                <div class="select-box">
                <select needle="needle" msg="您必须添加一种部门" class="select" datatype="*"  name="usercompany[departmentid]" class="select-default" id="departmentid" onchange="getGroup(this.value)">
                    <option value="0">请选择部门</option>
                    {if isset($dments)}
                        {volist name="dments" id="ds"}
                        {if condition="$ds.company_id eq $usercompany.company_id and $ds.pid eq '0'"}
                        <option value="{$ds.id}" {if $ds.id==$usercompany.departmentid}selected{/if}>{$ds.name}</option>
                        {/if}
                        {/volist}
                    {/if}
                </select>
               </div>
            </div>
            <div class="col-xs-offset-4"></div>
        </div>
        <div class="row cl authy"  {if $usercompany.job_title neq '2'} style='display:none' {/if} > 
              <label class="form-label  f-l ml-20">班组：</label>
                <div class="formControls  col-xs-6 col-sm-6">
                <div class="select-box">
                <select needle="needle" msg="您必须添加选择一种班组" class="select" datatype="*"  name="usercompany[departmentgroupid]" class="select-default" id="groupid">
                    <option value="0">请选择班组</option>
                     {if isset($dgrouplist)}
                     {volist name="dgrouplist" name="dgrouplist" id="dgp"}
                     {if condition="$dgp.pid eq $usercompany.departmentid and $dgp.pid neq '0'"}
                        <option value="{$dgp.id}" {if $dgp.id==$usercompany.departmentgroupid}selected{/if} >{$dgp.name}</option>
                     {/if}
                     {/volist}
                     {/if}
                </select>
               </div>
            </div>
            <div class="col-xs-offset-4"></div>
        </div>
		 <div class="row cl specialty">
             <label class="form-label  f-l ml-20">专业：</label>
                <div class="formControls  col-xs-6 col-sm-6">
                <div class="select-box">
                <select needle="needle" name="usercompany[specialty_id]" id="specialtyid" class="select" class="select-default" datatype="*" nullmsg="专业不能为空" >
                    <option value="0">请选择专业</option>
                    {if isset($specialtyList)}
                    {volist name="specialtyList" id="sList"}
                    <option value="{$sList.id}" {if $sList.id==$usercompany.specialty_id}selected{/if}>{$sList.name}</option>
                    {/volist}
                    {/if}
                </select>
               </div>
            </div>
            <div class="col-xs-offset-4"></div>
        </div>

        <script>

        </script>

        <div class="row cl">
            <label class="form-label f-l ml-20"><span class="c-red">*</span>状态：</label>
            <div class="formControls col-xs-6 col-sm-6 skin-minimal">
                <div class="radio-box">
                    <input type="radio" class="icheckbox-blue iradio-blue" name="usercompany[status]" id="status-1" value="0" {if condition="$usercompany.status eq '0'"}checked="checked"{/if} datatype="*">
                    <label for="status-1">启用</label>
                </div>
                <div class="radio-box">
                    <input type="radio" class="icheckbox-blue iradio-blue" name="usercompany[status]" id="status-0" {if condition="$usercompany.status eq '1'"}checked="checked"{/if} value="1" datatype="*">
                    <label for="status-0">禁用</label>
                </div>
            </div>
              <div class="col-xs-offset-4"></div>
        </div>
        <div class="row cl">
            <div class="ml-save">
                <button type="button" class="btn btn-primary radius ajaxFrom" fromid="form">&nbsp;&nbsp;保存&nbsp;&nbsp;</button>
                <button type="button" class="btn btn-default radius ml-20" onClick="layer_close();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__LIB__/Validform/5.3.2/Validform.min.js"></script> 
<script>
    
  // 公司选择 改变下属三级
    function getDepartment(e){
        $("#departmentid").attr("disabled",true);
        $.post('/admin/User/getDepartmentByCompanyId',
                {'company_id' : e},
                function(data){
                    $('#departmentid').html('<option value="0">请选择部门</option>');
                    var html = '<option value="0">请选择部门</option>';
                    $.each(data, function(index, item){
                        html += '<option value="'+item.id+'">'+item.name+'</option>'
                    });
                    $('#departmentid').html(html);
                    $("#departmentid").attr("disabled",false);
                });
        // 公司改变，下属二级重置
       $("#departmentid").html('<option value="0">请选择部门</option>');
       $("#groupid").html('<option value="0">请选择分组</option>');
    }
	
	//职能区分 内勤才有班组这些东西
	function Authority(){
		var job = $('#job_title').val();
		if(job==2){
			$('.authy').show();
			$('.usercompaysc').hide();
		} else {
			$('.authy').hide();
			$('.usercompaysc').show();
		}
		

	}
	
    // 获取部门下属分组
   function getGroup(e){
    $("#groupid").attr("disabled",true);
       $.post('/admin/User/getCompanyGroupList', 
               {'department_id' : e},
               function(data){
                   $('#groupid').html('');
                   var html = '<option value="0">请选择分组</option>';
                   $.each(data, function(index, item){
                       html += '<option value="'+item.id+'">'+item.name+'</option>'
                   });
                   $('#groupid').html(html);
                   $("#groupid").attr("disabled",false);
               });
       // 省级变动同时触发 县级 联动触发
       $("#groupid").html('<option value="0">请选择分组</option>');
   }


    $(function () {
        // js存在问题， 无法加
        // $("input[name='usercompany[status]'][value='{$usercompany.status ?? '1'}']").attr("checked",true);
        $("input[name='usercompany[status]']").click(function(){
            var ischeck = $(this).attr("checked");
            if(ischeck=="checked"){
                $(this).attr("checked",true);
                $(this).siblings().attr("checked", false);
            }else{
                $(this).attr("checked",true);
                $(this).siblings().attr("checked", false);
            }
            
        });
		
		{if $usercompany.job_title eq '2'}
				setTimeout(function () {
						$('#job_title').val(2);
						$('.authy').show();
						$('.usercompaysc').hide();

				},800);
		{/if}
		
        // $(".skin-minimal input").each(function(){
        //     $(this).click(function(){
        //         //当前元素选中 其他兄弟元素不选中
        //         $(this).attr("checked", true);
        //         $(this).siblings().attr("checked", false);
        //         console.log($(this).siblings().attr("checked"));
        //     });
        // });
        // 单选按钮框架样式无法加载
        // $('.skin-minimal input').iCheck({
        //     checkboxClass: 'icheckbox-blue',
        //     radioClass: 'iradio-blue',
        //     increaseArea: '20%'
        // });
        
        $("#form").Validform({
            tiptype:2,
            ajaxPost:true,
            showAllError:true,
            callback:function(ret){
                ajax_progress(ret);
            }
        });
    })
</script>
{/block}